//
//  ZTXGasHomeController.m
//  NtoccDriverNew
//
//  Created by 张天兴 on 2025/5/14.
//  Copyright © 2025 GCY. All rights reserved.
//

#import "ZTXGasHomeController.h"
#import "ZTXGasHomeCell.h"
#import "GasHomeVC.h"
#import "GasStationDriverManager.h"

@interface ZTXGasHomeController ()<UITableViewDataSource, UITableViewDelegate>

@property (strong , nonatomic)UITableView *tableView;

@property (strong , nonatomic)NSMutableArray *dataArray;

@property (nonatomic, strong) NSArray *bgImagArr;
@property (nonatomic, strong) NSArray *headerImagArr;
@property (nonatomic, strong) NSArray *deleteImagArr;
@property (nonatomic, strong) NSArray *titleArr;
@property (nonatomic, strong) NSMutableArray *numberDataArr;

@property (nonatomic, assign) NSInteger pageNum;
@property (nonatomic, strong) GasStationDriverModel *gasModel;


@end
static NSString *const cellID = @"ZTXGasHomeCell";

static const CGFloat cellHeight = 148;
@implementation ZTXGasHomeController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    _pageNum = 1;
    
    [self setupBaseView];
    
    [self freightIndexListRequest];
    self.numberDataArr = [@[] mutableCopy];
    self.titleArr = @[@"在线油卡",@"在线气卡",@"在线电卡"];
    self.bgImagArr = @[@"youBgImag1",@"youBgImag2",@"youBgImag3"];
    self.headerImagArr = @[@"youHeaderImag1",@"youHeaderImag2",@"youHeaderImag3"];
    self.deleteImagArr = @[@"lookDilet1",@"lookDilet2",@"lookDilet3"];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    self.tabBarController.tabBar.hidden = NO;
}

- (void)setupBaseView {
    
    self.tabBarController.navigationItem.title = @"在线汽油";
    self.tabBarController.navigationItem.rightBarButtonItem = nil;
    
    self.view.backgroundColor = BackgroundColor;
    
    [self.view addSubview:self.tableView];
}

- (void)freightIndexListRequest {
    @weakify(self)
    [GSDManager refreshUserInfo:^(GasStationDriverModel *userInfo) {
        @strongify(self)
        self.gasModel = userInfo;
        [self.numberDataArr addObject:[NSString stringWithFormat:@"%@元", [userInfo.oilCard isNotBlank] ? userInfo.oilCard : @"0.00"]];
        [self.numberDataArr addObject:[NSString stringWithFormat:@"%@元", [userInfo.gasCard isNotBlank] ? userInfo.gasCard : @"0.00"]];
        [self.numberDataArr addObject:[NSString stringWithFormat:@"%@元", [userInfo.electricityCard isNotBlank] ? userInfo.electricityCard : @"0.00"]];
        [self.tableView reloadData];
    }];
   
}



#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    return self.dataArray.count;
    return self.numberDataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZTXGasHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.bgImagView.image = [UIImage imageNamed:self.bgImagArr[indexPath.row]];
    cell.headerView.image = [UIImage imageNamed:self.headerImagArr[indexPath.row]];
    cell.selectedView.image = [UIImage imageNamed:self.deleteImagArr[indexPath.row]];
    cell.titleNameLabe.text = self.titleArr[indexPath.row];
    cell.moneyLabel.text = self.numberDataArr[indexPath.row];
//    cell.model = self.dataArray[indexPath.row];
    
    return cell;
}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return cellHeight;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001f;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    GasHomeVC *vc = [[GasHomeVC alloc] init];
    vc.gasModel = self.gasModel;
    if (indexPath.row == 0) {
        vc.typeStr = @"1";
    }else if (indexPath.row == 1){
        vc.typeStr = @"3";
    }else{
        vc.typeStr = @"2";
    }
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark - LazyLoad
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.frame = CGRectMake(0, 10, ScreenW, ScreenH - NavHeight - MenuBarHeight - 10);
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        
        //注册单元格
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ZTXGasHomeCell class]) bundle:nil] forCellReuseIdentifier:cellID];
    }
    
    return _tableView;
}

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}




@end
